import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入需要的组件

Vue.use(VueRouter)

// 路由表
/**
 * 懒加载
 * 只有点击了才加载该组件
 * 不会在网页一开始就加载全部组件
 * 好处：使页面更加流畅
 */
const routes = [
  // 登录页
  { path: '/login', name: 'login', component: () => import('@/views/login') },
  // 导航栏
  {
    path: '/',
    component: () => import('@/views/tabbar'),
    children: [
      // 默认子路由
      { path: '', name: 'Home', component: () => import('@/components/home') },
      { path: 'my', name: 'My', component: () => import('@/components/my') }
    ]
  },
  // 搜索页
  { path: '/search', name: 'search', component: () => import('@/components/search') },
  // 文章详细
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/components/article'),
    // 开启路由传参
    props: true
  },
  // 用户资料页
  {
    path: '/user/means',
    name: 'userMeans',
    component: () => import('@/components/user-means')
  },
  // 用户资料页
  {
    path: '/my/collection',
    name: 'myCollection',
    component: () => import('@/components/my/components/my-collection.vue')
  },
  // 用户资料页
  {
    path: '/my/history',
    name: 'myHistory',
    component: () => import('@/components/my/components/my-history.vue')
  },
  // 聊天的路由规则
  { path: '/chat', component: () => import('@/views/chat/index.vue'), name: 'chat' }
]

const router = new VueRouter({
  routes
})

export default router
